﻿<!DOCTYPE html>
<html>
<!-- 培训课程管理 -->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>
    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }

        .el-input__suffix {
            /* z-index: 9; */
        }

        .el-form-item__content {
            line-height: 28px !important;
        }
    </style>
</head>

<body>
    <div id="app" class="popupW50" v-cloak>
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="coursewareName">
                            <el-input type="text" v-model="Form.coursewareName" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{TrainingCourseManagement.CoursewareName+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.coursewareName">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>

                        </el-form-item>
                    </div>
                </el-col> 
                <el-col :span="11" offset="2">
                    <el-col>
                        <div class="elst-select-mini">

                            <el-form-item prop="classificationofCourseware">
                                <el-input size="mini">
                                    <template slot="prepend">
                                        {{TrainingCourseManagement.ClassificationofCourseware+mark.m}}
                                    </template>
                                    <treeselect v-model="Form.classificationofCourseware"
                                                :options="DepartmentList"
                                                :flat="true"
                                                slot="suffix"
                                                :disable-branch-nodes="true"
                                                style="line-height: 28px;width:70%;float: right;"
                                                placeholder="请选择" />
                                </el-input>
                                <span class="iputLineMust" v-if="!Form.classificationofCourseware">
                                    <!-- 必填项添加 -->
                                    <img src="/static/images/exclamation.png" alt="">
                                </span>
                            </el-form-item>

                        </div>
                    </el-col>
                </el-col>


                <el-col :span="7">
                    <div class="elst-select-mini">
                        <el-form-item prop="mark03">
                            <el-input type="text" v-model="Form.mark03" autocomplete="off" size="mini" disabled="false">
                                <template slot="prepend">
                                    {{TrainingCourseManagement.Trainer+mark.m}}
                                </template>
                            </el-input>
                            <span class="iputLineMust" v-if="!Form.mark03">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="3" offset="1">
                    <el-button class="ml10" type="primary" @click="addTrainer">{{col.btnSelectionTeachers}}
                    </el-button>
                </el-col>
                <!-- <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item prop="Trainer">
                            <label for="Trainingtime"
                                class="el-form-item__label">{{TrainingCourseManagement.Trainer+mark.m}}</label>
                            <span>{{Form.Trainer}}</span>
                            <el-button class="ml10" type="primary" @click="addTrainer">{{col.btnSelectionTeachers}}
                            </el-button>
                        </el-form-item>
                    </div>
                </el-col> -->
                <el-col :span="11" offset="2">
                    <div class="elst-select-mini">
                        <el-form-item prop="learningtime">
                            <el-input type="text" v-model="Form.learningtime" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{TrainingCourseManagement.Learningtime+mark.m}}
                                </template>
                            </el-input>

                            <span class="iputLineMust" v-if="!Form.learningtime">
                                <!-- 必填项添加 -->
                                <img src="/static/images/exclamation.png" alt="">
                            </span>
                        </el-form-item>
                    </div>
                </el-col>
                <!--<el-col :span="18">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input disabled type="text" v-model="Form.Courseware" autocomplete="off" size="mini"
                                readonly>
                                <template slot="prepend">
                                    {{TrainingCourseManagement.Courseware+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>-->
                <el-col :span="3">
                    <el-checkbox class="ml10" v-model="Form.encryptionornot" label="加密">
                    </el-checkbox>

                </el-col>
                <el-col :span="21">
                    <!--<el-upload class="fl" ref="Attachmentupload" action="/api/File/UpdateFile" multiple="true"
                               :on-preview="handlePreview" :on-remove="handleRemove"
                               :before-upload="CoursewareUploadbeforeupload" :auto-upload="true" :limit="1"
                               :show-file-list="false">
                        <el-button class="ml10" type="primary" size="mini" @click="btnAttachmentUpload">
                            {{col.btnImportcourseware}}
                        </el-button>
                    </el-upload>-->
                    <el-form-item prop="courseAttachment">

                        <label for="Trainingtime" class="el-form-item__label"
                               style="width: 100px;">{{TrainingCourseManagement.Courseware+mark.m}}</label>

                        <span>
                            <btn-uploadfile-input-kj v-loading.fullscreen.lock="fullscreenLoading" 
                         v-model="Form.attachmentName" text="导入课件" :fileid="Form.courseAttachment" ref="upbtn" :filename="Form.attachmentName" :showdownload="true" @changelodding="changelodding" @success="attachmentHandle"></btn-uploadfile-input-kj>
                        </span>
                        <span class="iputLineMust" v-if="!Form.attachmentName">
                            <!-- 必填项添加 -->
                            <img src="/static/images/exclamation.png" alt="">
                        </span>
                    </el-form-item>
            
                </el-col>

            </el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>-->
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
        <el-dialog title="选择培训老师" fullscreen="true" :visible.sync="ListItem.dialogVisible" @close='closeDialog'
            width="80%" height="80%" top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:100%;width:100%" frameborder="0"></iframe>
        </el-dialog>

    </div>
    <script type="text/javascript">
        var uploadText = "请选择上传文件";
        var app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                imageUrl: '',
                checked: true,
                value1: '',
                radio: '1',
                ListItem: ListItem,
                DepartmentList: [],
                currSeelctId: "",
                currSeelctRow: {
                    name: ""
                },
                fullscreenLoading: false,
                ClassificationofCourseware: [],
                formInline: {
                    model: {
                        CoursewareName: '',
                        ClassificationofCourseware: '',
                        Learningtime: '',
                        Encryptionornot: '',
                        Trainer: '',
                        Courseware: '',

                    },
                    offset: 0,
                    limit: 10
                },
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    CoursewareName: '',
                    ClassificationofCourseware: '',
                    learningtime: '',
                    encryptionornot: '',
                    Trainer: '',
                    Courseware: uploadText,
                    px_CourseTeacher: {
                        teacher:null
                    },
                    attachment: null,
                    attachmentName: '',
                    

                },
                //表单验证
                rules: {
                    coursewareName: [
                        verification.NotNull

                    ],
                    classificationofCourseware: [
                        verification.NotNull

                    ],
                    mark03: [
                        verification.NotNull

                    ],
                    learningtime: [
                        verification.NotNull,
                        { pattern: verification.IsDecimal.t, message: verification.IsDecimal.m },

                    ],
                    courseAttachment: [
                        verification.NotNull

                    ],

                }
            },

            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                handleRemove: function (file) {
                    console.log(file);
                },
                handlePreview: function (file) {
                    console.log(file.name);
                    window.open(file.url)
                },
                //上传附件文件的校验
                CoursewareUploadbeforeupload: function (file) {
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将附件名赋值到label上
                    this.Form.Courseware = file.name;
                    const extension = testmsg === 'doc'
                    const extension2 = testmsg === 'pdf'
                    const isLt10M = file.size / 1024 / 1024 < 10
                    if (!extension && !extension2) {
                        this.$message({
                            message: '上传文件只能是 doc、pdf格式!',
                            type: 'warning'
                        });
                    }
                    if (!isLt10M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt10M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt10M
                },
                btnAttachmentUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.fileAttachmentUpload != uploadText) {
                        this.$refs.Attachmentupload.clearFiles();
                        this.fileAttachmentUpload = file.name;
                    }
                    else {

                    }
                    this.$refs.Attachmentupload.submit();
                },
                //获取分页数据
                GetPageData: function (currentIndex) {

                    var mythis = this;
                    this.formInline.model.createFactory = parent.app.formInline.model.createFactory;
                    myAjax("post", this, '/api/PX_CourseClass/GetList', this.formInline, function (response) {

                        var data = MenuHelper(response.data.pageData, guidEmpty);
                        mythis.DepartmentList = data;
                        // mythis.DepartmentList.unshift({ id: guidEmpty, label: '无父级', Id: guidEmpty })//初始化无父级的选项
                    }, false);

                },
                //查询方法
                onSubmit: function () {
                    onSubmit(this);
                },
                btnUpLoad: function () {
                    this.$message({
                        message: '上传成功',
                        type: 'success'
                    });
                },
                //提交数据
                onSubmitForm: function (formName) {

                    if (this.Form.encryptionornot)
                        this.Form.encryptionornot = "1";
                    else
                        this.Form.encryptionornot = "0";
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/PX_Course/Save', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/PX_Course/get?id=' + this.id);
                    this.Form.learningtime = this.Form.learningtime + "";
                    if (this.Form.encryptionornot == '1')
                        this.Form.encryptionornot = true;
                },

               
                //列表选择触发
                UserInputStatistics: function (val, id) { DialogShow(this, val, "TrainingCourseManagementInputPerson.html", id); },
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //获取分页数据
                //GetPageData: function (currentIndex) { GetPageData(this, currentIndex, '/api/TrainingCourseManagement/GetList') },
                //pagesize改变 触发方法
                handleSizeChange: function (val) { handleSizeChange(this, val); },
                //跳页触发方法
                handleCurrentChange: function (val) { handleCurrentChange(this, val); },
                addTrainer: function (val, id) {
                    DialogShow(this, val, "TrainingPlanManagementluruInputTrainer.html", id);
                },
                changelodding: function (val) {
                    this.fullscreenLoading = val;
                },
                attachmentHandle: function (response, fileid, fileName, htmlid, b) {

                    this.Form.courseAttachment = fileid;
                    this.Form.attachmentName = fileName;
                    this.Form.htmlID = htmlid;
                    if (b) {
                        this.fullscreenLoading = false;

                    }

                },
                
            },
            updated: function () {
               // this.Form.Encryptionornot = eval(this.Form.Encryptionornot.toLowerCase());
            },
            mounted: function () {
                //初始化数据
                this.GetPageData(1);
                //列表高度自适应
                
                this.id = getUrlParam("id");
                this.getData();
                
                
                tablehigh(this);
            }

        });

        function MenuHelper(list, pid) {
            var result = [];
            list.forEach(function (v, i) {
                if (v.pId == pid) {
                    var obj = v;
                    obj.id = obj.id + '';
                    obj.label = obj.name + '';
                    var nextObj = MenuHelper(list, v.id);
                    if (nextObj.length > 0) {
                        obj.children = nextObj;
                    }
                }
                if (obj)
                    result.push(obj)
            })
            return result;
        }
    </script>
</body>

</html>